package com.ziyun.erp.modules.message.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ziyun.erp.modules.message.dao.MessageUserDao;
import com.ziyun.erp.modules.message.entity.MessageEntity;
import com.ziyun.erp.modules.message.entity.MessageUserEntity;
import com.ziyun.erp.modules.message.service.MessageUserService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("messageUserService")
public class MessageUserServiceImpl extends ServiceImpl<MessageUserDao, MessageUserEntity> implements MessageUserService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<MessageUserEntity> page = this.selectPage(
                new Query<MessageUserEntity>(params).getPage(),
                new EntityWrapper<MessageUserEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Page<MessageEntity> queryUserMassagePage(Page<MessageEntity> page, Map<String, Object> params) {

        return  page.setRecords(this.baseMapper.selectUserMessageList(page, params));
    }

    @Override
    @Cacheable(value="erp-user-message-cache" ,key="#p0.get('userId')")
    public List<MessageEntity> queryUserMessageList(Map<String, Object> params) {
        return this.baseMapper.selectUserMessageList(params);
    }

    /**
     * 标记已读
     * @param ids
     * @param userId
     */
    @Override
    public void markupRead(Integer[] ids, Long userId) {
        Map<String, Object> params = new HashMap<>();
        params.put("ids", ids);
        params.put("userId", userId);
       this.baseMapper.markupRead(params);
    }

}
